﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLNhaSach;
using Entities;
using System.Data.SqlClient;
using System.Data;

namespace DataAccessLayer
{
    public class ChiTietHoaDonDAL
    {
        DataService ds = new QLNhaSach.DataService();
        public int GetTongSachBanTrongThang(string thang, string nam, int maSach)
        {
            int kq = 0;
            try
            {
                String sql = "SELECT SUM(CTHD_SOLUONGBAN) FROM HOADONBANSACH, CHITIETHOADON, SACH WHERE";
                sql += " CTHD_MASACH = S_MASACH AND";
                sql += " CTHD_MAHOADON = HDBS_MAHOADON AND";
                sql += " CTHD_MASACH = " + maSach.ToString() + " AND";
                sql += " YEAR(HDBS_NGAYLAPHOADON)='" + nam + "' AND MONTH(HDBS_NGAYLAPHOADON) ='" + thang + "'";
                kq = int.Parse(ds.ExcuteQuery(sql).ToString());
            }
            catch (Exception)
            {
                throw;
            }
            return kq;

        }
        public int DeleteChiTietHoaDon(string maChiTietHoaDon)
        {
            int kq = 0;
            try
            {
                String sql = "DELETE FROM CHITIETHOADON WHERE CTHD_MACHITIETHOADON=" + maChiTietHoaDon;
                kq = int.Parse(ds.ExcuteInsert(sql).ToString());
            }
            catch (Exception)
            {
                throw;
            }
            return kq;

        }
        public DataTable GetChiTietHoaDonByID(int id)
        {
            DataTable dt = null;
            try
            {
                dt = new DataTable();
                string sql = "SELECT * FROM CHITIETHOADON WHERE CTHD_MAHOADON=" + id;
                dt = ds.GetTable(sql);
            }
            catch (Exception)
            {
                throw;
            }
            return dt;

        }
    }
}
